/* eslint no-return-await:0 */
const crypto = require('crypto');
const noteTypes =  [{
  name: '施工申请',
  enName: 'Construction',
}, {
  name: '高端控制系统变更申请',
  enName: 'RequestChange',
},{
  name: '变更申请回顾',
  enName: 'RequestChangeReview',
},{
  name: '外部测试申请',
  enName: 'ExternalTest',
},{
  name: '系统项目性测试申请',
  enName: 'ProjectTest',
}];

class UserModel {
  constructor() {

    this.teamList = ['A组', 'B组', 'C组', 'D组', '无'];

    this.equipmentList =  Array.from({ length: 10 }).map( (ele, index) => {
      return {
        id: index,
        scope: `设备类别${index % 3}`,
        equipmentname: `设备主名称${index}`,
        description: `这里是设备${index}的描述`,
        type: ['oracle', 'bnw', 'bhics', 'bhics2', 'it', 'workstation'][index % 6],
        radios: [['无', '有'], ['正常', '异常']][index % 2],  // 是什么选择
        hours: [index, index + 1, index + 2],  // 一天在几点巡查，以小时为单位
        weekDay: [1,2,3,4,5,6,7].slice(Math.round(Math.random() * (7 - 1) + 1), Math.round(Math.random() * (7 - 1) + 1)),
        label: ['白', '晚'][index % 2]
      }
    });

    this.userGroups = Array.from({ length: 10 }).map( (ele, index) => {
      return {
        id: index,
        groupname: `第${index}组`,
        description: `这里是第${index}组`,
      }
    });

    this.inspectionRecords = Array.from({ length : 60 }).map( (ele, index) => {
      return {
        id: index,
        inspectionTime: `${index}:00`,
        hour: index,  // 几点
        username: `用户${index}`,
        teamName: ['白班', '夜班'][index % 2],
        records: this.userGroups.map( (e, i) => {
          return {
            EquipmentId: e.id,
            equipmentState: i % 2,
            equipmentName: `设备${index}`,
          }
        })
      }
    });


    this.dutyShiftList = Array.from( { length : 10} ).map( (ele, index) => {
      return {
        // teamId: index % 4,
        id: index,
        teamName: this.teamList[index % 4],
        workBeginTime: new Date().getDate(),
        workEndTime: new Date().getDate(),
        teamMembers: `组员1 组员2 组员3`,
        workRecord: `这里是第${index % 5}组的值班记录`,
        posun: '测试',
        yichang: '异常',
        chaxundan: '查询单',
      }
    });

    // todo: type的这个整数能够设置和数组下标一致能省事

    this.userList = Array.from({ length: 10 }).map( (ele, index) => {
      let username, password, type, GroupId, token, groupname, avatar, teamname, phone, email;
      GroupId = this.userGroups[index % 5].id;
      groupname = this.userGroups[index % 5].groupname;
      teamname = this.teamList[index % 5];
      phone = '11717171717';
      email = '123123131322@qq.com';
      avatar = 'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1651253578,1410848472&fm=27&gp=0.jpg';
      switch (index % 5) {
        case 0:
          username = `user${index}`;
          password = `user${index}`;
          type = 1;
          break;
        case 1:
          username = `部门主管${index}`;
          password = `部门主管${index}`;
          type = 2;
          break;
        case 2:
          username = `1号审批员${index}`;
          password = `1号审批员${index}`;
          type = 3;
          break;
        case 3:
          username = `2号审批员${index}`;
          password = `2号审批员${index}`;
          type = 4;
          break;
        case 4:
          username = `超级管理员${index}`;
          password = `超级管理员${index}`;
          type = 100;
      }

      token = crypto.createHash('md5').update(`${index}+${username}+${password}`).digest('hex');

      return {
        id: index,
        username,
        password,
        phone,
        email,
        type,
        GroupId,
        token,
        groupname,
        teamname,
        extraAsideConfig: [{
          name: '百度',
          icon: 'activity',
          path: 'https://www.baidu.com',
          newWindow: true,
          external: true,
        }, {
          name: '必应',
          icon: 'activity',
          path: 'https://cn.bing.com',
          newWindow: true,
          external: true,
        }],
        avatar,
        browsePrivileges: {  // 用户浏览权限
          dashboardView: true,  // 首页通知浏览权限
          dashboardEdit: true,   // 首页通知编辑权限
          workingScheduleView: true,  // 排班表浏览权限
          workingScheduleEdit: true,  // 排班表编辑权限
          dutyShiftView: true,  // 交接班记录浏览权限
          dutyShiftEdit: true, // 交接班记录编辑权限
          inspectionListView: true, // 巡视检查单浏览权限
          inspectionSupport: false, // 博维Support确认权限（是否是博维Support人员）
          requestNoteView: true, // 申请权限
          approvalListView: true, // 审批权限
          equipmentControlView: true, // 设备管理权限
          userControlView: true, // 用户管理权限
          groupControlView: true, // 部门管理权限
          settingsView: true, // 个人设置权限
        },
        approvalPrivileges: [{
          step: 1,
          type: 'Construction',
        }],
      }
    });

    this.statusArr = ['未提交', '审批中', '进行中', '已关闭', '审批未通过'];

    this.requestNoteList = Array.from({ length: 8 }).map((ele, index) => {
      return {
        oid: `CR20190401${index}`,
        title: `申请单名称${index}`,
        type: noteTypes[index % 4].name,
        status: this.statusArr[index % 5],
        createdAt: '2019年4月1日',
      };
    });

    this.notes = [{
      isApprover: false,
      type: 'Maintain',
      requestNote: {
        title: '维保申请单0',
      },
      step: 1,
      reason: '',
      isRejected: 0,
    },{
      isApprover: false,
      type: 'Maintain',
      requestNote: {
        title: '维保申请单0',
      },
      step: 0,
      reason: '',
      isRejected: 0,
    },{
      isApprover: false,
      type: 'RequestChange',
      requestNote: {
        title: '申请单0',
      },
      step: 1001,
      reason: '',
      isRejected: 0,
    }, {
      isApprover: false,
      type: 'RequestChange',
      requestNote: {
        title: '申请单1',
      },
      step: 1002,
      reason: '',
      isRejected: 0,
    }, {
      isApprover: false,
      type: 'RequestChange',
      requestNote: {
        title: '申请单2',
      },
      step: 1003,
      reason: '',
      isRejected: 0,
    }, {
      isApprover: false,
      type: 'RequestChange',
      requestNote: {
        title: '申请单3',
      },
      step: 1003,
      reason: '被拒绝了',
      isRejected: 1004,
    }, {
      isApprover: false,
      type: 'RequestChange',
      requestNote: {
        title: '申请单4',
      },
      step: 1004,
      reason: '',
      isRejected: 0,
    }, {
      isApprover: false,
      type: 'RequestChange',
      requestNote: {
        title: '申请单5',
      },
      step: 2000,
      reason: '',
      isRejected: 0,
    }, {
      isApprover: false,
      type: 'Construction',
      requestNote: {
        title: '申请单6',
        files: [{
          name: '附件名',
          url: '/url',
        }],
        projectName: '项目名称',
        applicantName: '申请人姓名',
        departmentName: '123',
        applicantPhone: '123',
        beginTime: '123',
        endTime: '12',
        unitName: '2',
        contactName: '123',
        operationArea: '123',
        projectDescription: '123',
        isInfluenceSystemRun: '是',
        isInfluenceSystemRunInfo: '123',
        isChangeSystem: '是',
        isChangeSystemInfo: '123',
        isHaveRisk: '是',
        isHaveRiskInfo: '123',
      },
      step: 0,
      reason: '',
      isRejected: 0,
    }, {
      isApprover: false,
      type: 'Construction',
      requestNote: {
        title: '申请单7',
        projectName: '项目名称',
        applicantName: '申请人姓名',
        departmentName: '123',
        applicantPhone: '123',
        beginTime: '123',
        endTime: '12',
        unitName: '2',
        contactName: '123',
        operationArea: '123',
        projectDescription: '123',
        isInfluenceSystemRun: '是',
        isInfluenceSystemRunInfo: '123',
        isChangeSystem: '是',
        isChangeSystemInfo: '123',
        isHaveRisk: '是',
        isHaveRiskInfo: '123',
      },
      step: 1,
      reason: '',
      isRejected: 0,
    }, {
      isApprover: false,
      type: 'Construction',
      requestNote: {
        title: '申请单8',
        projectName: '项目名称',
        applicantName: '申请人姓名',
        departmentName: '123',
        applicantPhone: '123',
        beginTime: '123',
        endTime: '12',
        unitName: '2',
        contactName: '123',
        operationArea: '123',
        projectDescription: '123',
        isInfluenceSystemRun: '是',
        isInfluenceSystemRunInfo: '123',
        isChangeSystem: '是',
        isChangeSystemInfo: '123',
        isHaveRisk: '是',
        isHaveRiskInfo: '123',
      },
      step: 2,
      reason: '',
      isRejected: 0,
    }, {
      isApprover: false,
      type: 'Construction',
      requestNote: {
        title: '申请单9',
        projectName: '项目名称',
        applicantName: '申请人姓名',
        departmentName: '123',
        applicantPhone: '123',
        beginTime: '123',
        endTime: '12',
        unitName: '2',
        contactName: '123',
        operationArea: '123',
        projectDescription: '123',
        isInfluenceSystemRun: '是',
        isInfluenceSystemRunInfo: '123',
        isChangeSystem: '是',
        isChangeSystemInfo: '123',
        isHaveRisk: '是',
        isHaveRiskInfo: '123',
      },
      step: 3,
      reason: '',
      isRejected: 0,
    },  {
      isApprover: false,
      type: 'Construction',
      requestNote: {
        title: '申请单10',
        projectName: '项目名称',
        applicantName: '申请人姓名',
        departmentName: '123',
        applicantPhone: '123',
        beginTime: '123',
        endTime: '12',
        unitName: '2',
        contactName: '123',
        operationArea: '123',
        projectDescription: '123',
        isInfluenceSystemRun: '是',
        isInfluenceSystemRunInfo: '123',
        isChangeSystem: '是',
        isChangeSystemInfo: '123',
        isHaveRisk: '是',
        isHaveRiskInfo: '123',
      },
      step: 1000,
      reason: '',
      isRejected: 0,
    },  {
      isApprover: false,
      type: 'Construction',
      requestNote: {
        title: '申请单11',
        projectName: '项目名称',
        applicantName: '申请人姓名',
        departmentName: '123',
        applicantPhone: '123',
        beginTime: '123',
        endTime: '12',
        unitName: '2',
        contactName: '123',
        operationArea: '123',
        projectDescription: '123',
        isInfluenceSystemRun: '是',
        isInfluenceSystemRunInfo: '123',
        isChangeSystem: '是',
        isChangeSystemInfo: '123',
        isHaveRisk: '是',
        isHaveRiskInfo: '123',
      },
      step: 2000,
      reason: '',
      isRejected: 0,
    },  {
      isApprover: true,
      type: 'Construction',
      requestNote: {
        title: '申请单12',
        projectName: '项目名称',
        applicantName: '申请人姓名',
        departmentName: '123',
        applicantPhone: '123',
        beginTime: '123',
        endTime: '12',
        unitName: '2',
        contactName: '123',
        operationArea: '123',
        projectDescription: '123',
        isInfluenceSystemRun: '是',
        isInfluenceSystemRunInfo: '123',
        isChangeSystem: '是',
        isChangeSystemInfo: '123',
        isHaveRisk: '是',
        isHaveRiskInfo: '123',
      },
      step: 3,
      reason: '',
      isRejected: 0,
    }, {
      isApprover: false,
      type: 'Construction',
      requestNote: {
        title: '申请单13',
        projectName: '项目名称',
        applicantName: '申请人姓名',
        departmentName: '123',
        applicantPhone: '123',
        beginTime: '123',
        endTime: '12',
        unitName: '2',
        contactName: '123',
        operationArea: '123',
        projectDescription: '123',
        isInfluenceSystemRun: '是',
        isInfluenceSystemRunInfo: '123',
        isChangeSystem: '是',
        isChangeSystemInfo: '123',
        isHaveRisk: '是',
        isHaveRiskInfo: '123',
      },
      step: 3,
      reason: '拒绝的原因拒绝的原因拒绝的原因拒绝的原因',
      isRejected: true,
    }];

    this.inspectionList = Array.from({ length: 10 }).map((ele, idx) => {
      return {
        oid: `XF-2019-05${idx}`,
        title: `巡视检查单${idx}`,
        type: ['oracle', 'bnw', 'bhics', 'bhics2', 'it', 'workstation'][idx % 6],
        createdTime: `2019年5月1日`,
        isAbnormal: !!(idx % 2),
        abnormalRecord: !!(idx % 2) ? '这里是异常记录' : '',
        signatory: ['白班-张三', '晚班-李四', '博维-王五'],
      }
    });

    this.inspectionWeekRecords = Array.from({ length : 40 }).map((ele, idx) => {
      return {
        id: idx,  // 记录自身的id
        EquipmentId: idx,  // 设备id
        equipmentName: `设备${idx}`,  // 设备名称
        scope: `设备类别${idx}`,
        equipmentState: Array.from({length: 3}).map((e, i) => {
          return {
            weekday: Math.round(Math.random() * ( 7 - 1 ) + 1),
            state: i % 2,
            label: ['白', '晚'][i % 2],
          }
        })
      }
    });
  }

  async findUserProfile(token) {
    let user;
    this.userList.forEach((ele, idx) => {
      if(ele.token === token){
        user = ele;
      }
    });
    return user;
  }
}

module.exports = new UserModel();
